Ext.define('CDR.view.manager.user.UserFactory', {
	extend: 'Ext.Panel',
	alias : 'widget.userfactory',
	title: 'User Factory',
	selectedFactoryId : 0,
	profileCenter : null,
	initComponent: function() {
		var me = this;
		me.callParent();
		//me.user = Ext.createWidget('user',{pbxFactory:me});
		//this.addItem('All','all');
		//this.addItem('Admin','admin');
		//this.addItem('Contact','contact');
	},
	layout:'anchor',
	addItem: function(name, id){
		var me = this;
		this.add({
			obId: id,
			anchor:'100%',
			xtype : 'button',
            text    : name,
			scale: 'large',
			margin: '0 0 10px 0',
			enableToggle: true,
			toggleGroup:'serviceprovider_bnt',
			handler: function(){
				me.selectedFactoryId = this.obId;
				//get list
				if (me.user) {
					var store = me.user.view.store;
					store.setProxy({
					  type: 'ajax',
					  url : 'list-user-view?type=' + me.selectedFactoryId,
					  reader: {
						  type: 'json',
						  root: 'results'
					  }
					});
					store.load();
				}
			}
		});
	},
	submitOk: function(data) {
		this.addItem(data.name, data.id);
	},
	listeners: {
		expand : function(){
			this.profileCenter.removeAll(false);
			this.profileCenter.add(this.user);
		}
	}
});